package com.ls.blog.controller;


import static com.ls.blog.common.consts.Methods.*;

import com.ls.blog.common.valid.ReqId;
import com.ls.blog.common.valid.Select;
import com.ls.blog.dto.CommentDTO;
import com.ls.blog.dto.LikeDTO;
import com.ls.blog.dto.Recodes;
import com.ls.blog.entity.Comment;
import com.ls.blog.service.ArticleService;
import com.ls.blog.service.CommentService;
import com.ls.blog.utils.R;
import com.ls.blog.utils.Result;
import com.ls.blog.vo.CommentVO;
import com.ls.blog.vo.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lishun
 * @since 2022-01-14
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论模块")
public class CommentController {

    @Autowired
    private CommentService commentService;
    @Autowired
    private ArticleService articleService;

    //查询评论列表
    @PostMapping("/home/list")
    public Result<Recodes<CommentDTO>> comments(@Validated(value = {ReqId.class, Select.class}) @RequestBody PageVO pageVO) {
        return R.ok(commentService.listCommentByArticleIdId(pageVO));
    }

    @PostMapping("/home/replys")
    public Result<Recodes<CommentDTO>> replys(@Validated(value = {ReqId.class, Select.class}) @RequestBody PageVO pageVO) {
        return R.ok(commentService.replys(pageVO));
    }


    //查询所有评论
    @PostMapping("/getCommentByPage")
    public Recodes<CommentDTO> getCommentByPage(PageVO pageVO){
        return commentService.getCommentByPage(pageVO);
    }

    //根据评论人姓名查询评论
    @GetMapping("/comments")
    public List<Comment> findCommentByNickname(String nickname){
        return commentService.findCommentByNickname(nickname);
    }


    @ApiOperation(value = "文章评论")
    @PostMapping("/comments")
    public Result<?> post(@RequestBody CommentVO commentVO) {
        commentService.saveComment(commentVO);
        return R.ok();
    }

    @ApiOperation(value = "删除评论")
    @DeleteMapping("/deleteComment")
    public Result<?> delete(Integer id){
        commentService.deleteComment(id);
        return R.ok();
    }

    @ApiOperation(value = "审核评论列表")
    @PostMapping("/sureComments")
    public  Result<Recodes<CommentDTO>> sureComments(@RequestBody PageVO pageVO){
        Recodes<CommentDTO> commentDTORecodes = commentService.sureComments(pageVO);
        return R.ok(commentDTORecodes);
    }

    @ApiOperation(value = "批量审核",httpMethod = PUT)
    @PutMapping("/batchSureComments")
    public  Result<Recodes<CommentDTO>> batchSureComments(@RequestBody List<Integer> ids){
        commentService.batchSureComments(ids);
        return R.ok();
    }

    @ApiOperation(value = "拒绝审核",httpMethod = PUT)
    @PutMapping("/rejectSureComments")
    public  Result<Recodes<CommentDTO>> rejectSureComments(@RequestBody List<Integer> ids){
        commentService.rejectSureComments(ids);
        return R.ok();
    }


    @ApiOperation(value = "评论点赞",httpMethod = GET)
    @GetMapping("/like")
    public Result<LikeDTO> commentUp(Integer id){

        return R.ok(commentService.commentUp(id));
    }




}

